package com.stars.easyms.logger.config;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.PriorityOrdered;

/**
 * <p>className: EasyMsLoggerPostProcessor</p>
 * <p>description: </p>
 *
 * @author guoguifang
 * @date 2019-12-25 16:22
 * @since 1.5.0
 */
public class EasyMsLoggerPostProcessor implements BeanFactoryPostProcessor, ApplicationContextAware, PriorityOrdered {

    private ConfigurableApplicationContext configurableApplicationContext;

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        EasyMsLoggerInitializer.init(configurableApplicationContext);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.configurableApplicationContext = (ConfigurableApplicationContext) applicationContext;
    }

    @Override
    public int getOrder() {
        return HIGHEST_PRECEDENCE;
    }

}